package event;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class MyFrame05 extends JFrame implements MouseMotionListener,MouseListener {
	
	JLabel lbl = new JLabel("현재좌표");
	private Canvas can = new Canvas();
	
	public MyFrame05() {
		this.setBounds(100,100,500,400);
		this.setVisible(true);
		
		can.setBackground(Color.red);
		this.add(can);
		this.add(lbl, BorderLayout.NORTH);
		
		can.addMouseMotionListener(this);
		can.addMouseListener(this);
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new MyFrame05();
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		Graphics g = can.getGraphics();
		int x = e.getX();
		int y = e.getY();
		int size = 100;
		g.drawOval(x-50, y-50, size, size);
	}
	@Override
	public void mouseMoved(MouseEvent ev) {
		// TODO Auto-generated method stub
		int x = ev.getX();
		int y = ev.getX();
		lbl.setText("x=" + x + ",y=" + y);
		
	}

}
